<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <label class="el-form-item-label">任务名称</label>
        <el-input
          v-model="query.name"
          clearable
          placeholder="任务名称"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud" />
      </div>

      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <!--<crudOperation :permission="permission" />-->
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          size="small"
          label-width="80px"
        />
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button
            :loading="crud.cu === 2"
            type="primary"
            @click="crud.submitCU"
          >确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="index" width="40" />
        <el-table-column prop="name" label="任务名称" />
        <el-table-column prop="taskDefKey" label="任务KEY" />
        <el-table-column prop="startTime" label="开始时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="结束时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="duration" label="耗时(ms)" />
        <el-table-column prop="dueDate" label="到期时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.dueDate) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudActHiTaskinst from '@/api/actHiTaskinst'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  id: null,
  procDefId: null,
  taskDefKey: null,
  procInstId: null,
  executionId: null,
  name: null,
  parentTaskId: null,
  description: null,
  owner: null,
  assignee: null,
  startTime: null,
  claimTime: null,
  endTime: null,
  duration: null,
  deleteReason: null,
  priority: null,
  dueDate: null,
  formKey: null,
  category: null,
  tenantId: null
}
export default {
  name: 'ActHiTaskinst',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '已办任务',
      url: 'api/actHiTaskinst',
      idField: 'id',
      sort: 'id,desc',
      crudMethod: { ...crudActHiTaskinst }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'actHiTaskinst:add'],
        edit: ['admin', 'actHiTaskinst:edit'],
        del: ['admin', 'actHiTaskinst:del']
      },
      queryTypeOptions: [{ key: 'name', display_name: '任务名称' }],
      rules: {
        startTime: [{ required: true, message: '不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped></style>
